package com.terry.test3;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 叠积木  返回最大层数
 * 样例输入
 * 3 6 6 3
 * 样例输出
 * 3
 *
 * 样例输入
 * 1 4 2 3 6
 * 杨烈输出
 * -1
 *
 * @author 小八
 * @date 2023年02月13日14:20
 */
public class Title32 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextLine()){
          String[] splits = in.nextLine().split(" ");
          int[] arr = new int[splits.length];
            for (int i = 0; i < splits.length; i++) {
                arr[i] = Integer.parseInt(splits[i]);
            }
            Arrays.sort(arr);
            int sum = Arrays.stream(arr).sum();
            int index = arr.length;
            while(index>1){
                if(sum%index == 0){
                   int piece = sum/index;
                    if(arr[arr.length-1]<=piece && isCombine(arr,piece,arr.length-1,0,0,new int[arr.length])){
                        System.out.println(index);
                        break;
                    }
                }
                index--;
            }
        }
    }

    public static boolean isCombine(int[] arr,int piece,int index,int curLen,int curPiece,int[] mark){
        if(curLen == arr.length){ //一定能平分，所以只要走完了 就能成功
            return true;
        }
        if(curPiece == piece){
            return isCombine(arr,piece,arr.length-1,curLen,0,mark);
        }

        for(int i=index;i>=0;i--){
            if(mark[i]==1 || arr[i]+curPiece>piece){
                continue;
            }
            mark[i] = 1;
            if(isCombine(arr,piece,i-1,curLen+1,curPiece+arr[i],mark)){
                return true ;
            }
            mark[i] = 0;
//            if(curPiece == 0){
//                return false;
//            }
        }
        return false ;
    }
}
